<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.util.*"%>
<%@ page import="com.google.gson.Gson" %>
<%@ page import="bean.signal_path" %>
<%--
  Created by IntelliJ IDEA.
  User: hongquanzhou
  Date: 2020-06-07
  Time: 15:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8"%>
<html>
<head>
    <title>signal_show</title>
</head>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<body>

    <div id="nav">
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link " href="welcome.jsp">首页</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="signal_analysis.html">数据分析<span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item ">
                        <a class="nav-link " href="model_construct_AlexNet.html">模型构建与下载</a>
                    </li>
                    <li class="nav-item ">
                        <a class="nav-link" href="statistic_information.html">统计信息</a>
                    </li>
                </ul>
                <h5 style="height: 10px;" align="right"><a id="username" class="user"></a> &nbsp;</h5>
            </div>
        </nav>
    </div>


    <div style="width: 24%;float:left">
        <div style="height: 500px;width:100%;overflow: auto;margin-top: 10px;margin-left: 10px">
            <table id="select_signal">
                <%
                    request.setCharacterEncoding("utf-8");
                    BufferedReader br = new BufferedReader(new InputStreamReader((request.getInputStream())));
                    String line = null;
                    int count = 0;
                    Gson gson = new Gson();
                    signal_path s = null;

                    while((line = br.readLine())!=null)
                    {

                        if(count%4==3) {
                            out.print("<tr>");
                            s = gson.fromJson(line, signal_path.class);
                            out.print("<th>"+s.getString()+"</th>"+"<th><input type='checkbox'></th>");
                            out.print("<th style='display: none'>"+s.getPath()+"</th>");
                            out.print("</tr>");
                        }
                        count++;
                    }

                %>
            </table>
        </div>
        <div style="margin-left: 30px;margin-top: 10px">
            <input type="button" id="time_zone" value="时域"/>
            <input type="button" id="frequence_zone" value="频域"/>
        </div>
    </div>
    <div style="width: 76%;height:600px;float: left;margin-top: 10px">
        <div id="graph_container1" style="width: 50%;height: 600px;float: left;text-align: center">
            <div style="width: 100%;height:20px;float: left">
                <p>时域图</p>
            </div>
            <div>
                <img src="../resource/pic/时域.jpeg" width="500px" style="margin-top: 10px">
            </div>
        </div>
        <div id="graph_container2" style="width: 50%;height: 600px;float: left;text-align: center">
            <div style="width: 100%;height:20px;float: left">
                <p>频域图</p>
            </div>
            <div>
                <img src="../resource/pic/频域.tiff" width="500px" height="400px">
            </div>

        </div>
    </div>



</body>
<script>
    var signalList = new Array();
    window.onload = function (ev) {
        getUser();
        getSignalDateName();
        downloadDate();
    };
    function getUser() {
        var user = document.getElementById("username");
        var xhr = new XMLHttpRequest();
        xhr.open("POST","../GetUserName",true);
        xhr.send();
        xhr.onreadystatechange = function (ev1) {
            if(xhr.readyState==4&&xhr.status==200)
            {
                var content = xhr.responseText;
                if(content=="no,relogin")
                {
                    user.innerText = "请重新登录";
                    user.href = "login.jsp";
                }
                else
                {
                    user.innerText = content;
                    user.href = "user.html";
                }
            }

        }
    }
    function getSignalDateName() {
        var table = document.getElementById("select_signal");
        var trs = table.getElementsByTagName('tr');
        for(var i=0;i<trs.length;i++)
        {
            var object = new Object();
            var tds=trs[i].getElementsByTagName("th");
            object.string = tds[0].innerHTML;
            object.path = tds[2].innerHTML;
            signalList.push(object);
        }

    }
    function downloadDate() {
        var xhr = new XMLHttpRequest();
        xhr.open("POST","../DownLoadSignalData",true);
        xhr.send(JSON.stringify(signalList));
        alert(JSON.stringify(signalList))
        xhr.onreadystatechange = function (ev) {
            if(xhr.readyState==4&&xhr.status==200)
            {
                alert("ok");
            }
        }

    }
</script>
</html>
